home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
getkey11.zip
/
GETKEY.DOC
< prev
next >
Wrap
Text File
|
1993-12-06
|
5KB
|
140 lines
GetKey 1.11
December 6, 1993
A Batch File enhancing command
to allow full usage of the keyboard
Copyright (c) 1992-1993 Chad Knudson, All Rights Reserved
GetKey is a command to use in Batch files to allow polling for any
keypress of the keyboard. It was written for developing a menu
system in DOS Batch (.BAT) files.
Setup
-----
Operation of GetKey is quite simple. You will want to place the
GETKEY.EXE file either in the directory that your .BAT file resides
or in a directory in your DOS PATH statement. That's all that you
need to do for setting up GetKey.
Operation
---------
GetKey is designed for use in .BAT files. When you call GetKey in a
.BAT file, it will wait until the next keypress occurs and then will
store a textual representation of that key in the DOS environment
variable KEY. Here are some samples of what GetKey places in KEY:
────────────┬───────────────────────────────────────────────────────
KEY= │ Keystroke
────────────┼───────────────────────────────────────────────────────
F10 │ Function key F10 pressed
A │ Capital A pressed
CTRL-HOME │ CTRL and HOME keys pressed simultaneously
ALT-X │ ALT and X keys pressed simultaneously
ESC │ Escape key pressed
ALT-F12 │ ALT and Function Key F12 pressed simultaneously
??? │ 5 pressed on numeric keypad when NumLock off
As you can see, it allows for nearly any keystroke combination to be
polled. If GetKey doesn't recognize the keypress, it places three
question marks in KEY. The majority of keypresses are available to
you to use, but there are a few that I excluded. To make sure that
the keypress you wish to use is valid, try it manually. Type
GETKEY, press the keypress in question, and type SET at the DOS
prompt to see your current environment setting. (A sample of how to
do this is included in the file TESTKEY.BAT which will probably
suffice for any testing you need to do.)
Using GetKey in a .BAT file
---------------------------
Below is a sample batch file (also included in this .ZIP is a file
RUNME.BAT, which is a more in-depth demonstration) which
demonstrates how you can utilize GetKey in your own batch file.
TESTME.BAT
───┬────────
1 │ @Echo off
2 │ Cls
3 │ Echo This is a simple demonstration of how to use GETKEY in your own
4 │ Echo .BAT files. It is not intended to be an exhaustive demonstration,
5 │ Echo but rather
6 │ Echo to get you going in the right direction.
7 │ Echo.
8 │ Echo.
9 │ Echo On
10 │ :start
11 │ Echo -={ Press <F1> to continue }=-
12 │ GETKEY
13 │ IF %KEY%==F1 goto item1
14 │ goto start
15 │ :item1
16 │ Echo.
17 │ Echo Good! You're getting the hang of it.
───┴───────
Notes About Specific Lines:
Line 10 This is a label in a batch file, it enables us to use the
goto command to transfer control within the batch file.
This particular label will set up the starting point of our
menu, and we'll always return to this when we've completed
another task. See the included RUNME.BAT file for a better
example of how this works.
Line 12 Call GETKEY
Line 13 Test the environment variable KEY to see if it equals one of
our menu choices.
Line 14 If it made it this far, no menu choice was selected so we
should go back and get a valid menu selection.
About GetKey and CKWare
-----------------------
GetKey was written by Chad Knudson while attending the University of
North Dakota majoring in Computer Science and Mathematics. It was
written in 'C' and compiled with Microsoft C 7.0.
Chad has developed a number of utilities for Bulletin Board Systems
as well as DOS utilities. To see the latest collection of CKWare
products, call City Lites BBS (701) 772-5399.
If you feel that GETKEY is useful to you, feel free to use it. If
you'd like to make a donation to the author, you're certainly
encouraged to but not obligated. Send donations to:
CKWare (GetKey)
Chad Knudson
P.O. Box 112
Towner, ND 58788
I can also take your questions, comments, and bug reports via
e-mail at:
Internet
──────────
knudson@cs.und.nodak.edu
RIME
──────────
->CITYLITE
FIDO
──────────
1:14/644
Credits
-------
A special thanks goes out to H. D. Todd, Wesleyan University, for
steering me in the right direction as to how one could manipulate
variables in the parent process' environment (the documentation in
the C Compilers said that this could not be done, at least not using
the putenv() function that the compiler provides.) Without his help
this program wouldn't have been possible.